<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./vue.js"></script>
</head>

<body>
    <div id="wrap">
        <p>这个是父元素</p>
        <!-- 自定义一个函数，但是需要绑定在一个自定义名字的子组件上 -->
        <my-com @zidingyi="fatherfn"></my-com>
    </div>


    <template id="demo1">
        <div>
            <p>{{ messages }}</p>
            <button @click="sonfn">click me</button>
            <button @click="sonfn1">click me 变值</button>
        </div>
    </template>
</body>
<script>

    Vue.component('myCom', {
        template: '#demo1',
        data() {
            return {
                messages: '这个是子组件'

            }
        },
        methods: {
            sonfn() {
                this.$emit('zidingyi', this.messages)
            },
            sonfn1() {
                this.messages = '这是改变之后的子元素'
            }
        }
    })


    new Vue({
        el: '#wrap',
        methods: {
            fatherfn(val) {
                console.log(val)
            }
        }
    })

</script>

</html>